package com.ytjj.qmyx.mall.controller;

import com.ytjj.common.utils.AliyunOSSClientUtil;
import com.ytjj.qmyx.mall.mapper.DynamicMapper;
import com.ytjj.qmyx.mall.model.Dynamic;
import com.ytjj.qmyx.mall.model.DynamicExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *
 * @version 1.0
 * 
 */
@Controller
@Slf4j
public class YybController {

    @RequestMapping("/yyb_response")
    public String yxbResponse(@RequestParam(value = "authorization_code",required = false) String authorization_code
            ,@RequestParam(value = "state",required = false) String state){
        log.info("=========>收到code: {} ,state :{}" , authorization_code,state);
        return "SUCCEED";
    }


    @Resource
    DynamicMapper DynamicMapper;

    /**
     * 刷新视频的高宽
     * @return
     */
    @RequestMapping("/dynamicpd")
    public String dynamicpd(){
        List<Dynamic> list= DynamicMapper.selectByExample(new DynamicExample());
        for(Dynamic d: list){
            if("video".equals(d.getDynamicType())){
                Map<String,Object> reuslt = AliyunOSSClientUtil.getScreenshot(d.getVideo());
                if(reuslt!=null){
                    d.setHeight((int)reuslt.get("videoHigh"));
                    d.setWidth((int)reuslt.get("videoWide"));
                }
                DynamicMapper.updateByPrimaryKeySelective(d);
            }
        }
        return "SUCCEED";
    }

}
